package com.jci.vsd.activity.UserInfo;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.jci.vsd.R;
import com.jci.vsd.activity.BaseActivity;
import com.jci.vsd.activity.DownloadIntentService;
import com.jci.vsd.constant.MySpEdit;
import com.jci.vsd.utils.Utils;
import com.jci.vsd.view.widget.SimpleToast;


import butterknife.BindView;

/**
 * Created by liqing on 18/7/9.
 * 版本信息
 */

public class VersionInfoActivity extends BaseActivity {
    @BindView(R.id.tv_sure)
    TextView tvSure;
    @BindView(R.id.tv_current_version)
    TextView tvCurrentVersion;

    @BindView(R.id.tv_last_version)
    TextView tvLastVersion;

    //button_back
    @BindView(R.id.button_back)
    ImageButton backBtn;

    @BindView(R.id.textview_title)

    TextView tvTitle;

    private Context mContext;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_version_info);
        mContext = VersionInfoActivity.this;
        tvTitle.setText("版本信息");
        initViewEvent();
        getVersion();
    }

    private void getVersion() {
        String currentVersion = Utils.getVersionName();
        String lastVersion = MySpEdit.getInstance().getLastVersion();
        tvCurrentVersion.setText(currentVersion);
        tvLastVersion.setText(lastVersion);
        if (currentVersion.equals(lastVersion)) {
            tvSure.setVisibility(View.GONE);
        } else {
            tvSure.setVisibility(View.VISIBLE);
        }

    }

    @Override
    protected void initViewEvent() {
        tvSure.setOnClickListener(this);
        backBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {

        super.onClick(view);
        if (view.getId() == R.id.tv_sure) {
            SimpleToast.toastMessage("将为您后台下载", Toast.LENGTH_SHORT);
            //下载apk
            Intent intent = new Intent(mContext, DownloadIntentService.class);
            startService(intent);
        } else if (view.getId() == R.id.button_back) {

            this.finish();
        }
    }


}
